unit fileload;
interface
uses crt, langs;
type
	switch = 0..3; //more ain't necessary ;)
var
	outFile, inputFile : text;
	save : string;
	ende : string[2];
	saveInd : switch;
	fileLoaded : boolean;
function yn(src : string) : switch;
procedure fromFile(src : string);
procedure toFile(src : string);
implementation
function yn(src : string) : switch;
	begin
	if (src = 'y') or (src = 'Y') then yn := 1 //if yes
	else if (src = 'n') or (src ='N') then yn := 0 // neither yes nor no
	else yn := 2; // if no
		{
		0 - no
		1 - yes
		2 - neither yes nor no
		}
	end;
procedure fromFile(src, txt : string);
	var t : string;
	begin
	//setting value
	txt := '';
	correctPath := false;
	//end of setting value
	writeln(language[16], ende, language[17]);
	readln(save);
	saveInd := yn(save); //whether yes or no
	if saveInd = 2 then fromFile(src); // repeat muahahahaha!
	if saveInd = 1 then begin //if yes
		fileLoaded := true;
		repeat
			clrscr;
			writeln(language[11]); 
			readln(path);
			clrscr;
			assign(inputFile, path);
			{$I-} //io checking off
			reset(outFile); //read only
			if ioresult <> 0 then writeln('The file does not exist. Please specify a path to an existing file.')
			else correctPath := true;
			{$I+}
		until correctPath = true;
		repeat
			readln(inputFile, t);
			txt := txt + t;
		until eof(inputFile);
		end
	else fileLoaded := false;
	end;
procedure toFile(src : string);
	var
		path : string;
		correctPath : boolean;
		io : byte;
		existance : boolean;
	begin
	//setting value
	correctPath := false;
	//end of setting value
	writeln(language[9], ende, language[10]);
	readln(save);
	saveInd := yn(save); //whether yes or no
	if saveInd = 2 then toFile(src); // repeat muahahahaha!
	if saveInd = 1 then begin // if yes
		repeat
			clrscr;
			writeln(language[11]);
			readln(path);
			clrscr;
			assign(outFile, path);
			{$I-} //io checking off
			reset(outFile); //read only
			if ioresult <> 0 then begin rewrite(outFile);// if the file doesn't exist it will give an output error
			existance := false;
			end;
			io := ioresult; //ioresult could change
			if io <> 0 then writeln(language[13]); //for example linux path on windows
			if io = 0 then correctPath := true;
		until
			correctPath = true;
		{$I+} // io checking on
		close(outFile);
		repeat
			saveInd := 2;
			writeln(language[13]);
			readln(save);
			saveInd := yn(save); //whether yes or no
		until
			saveInd <> 2;
		if saveInd = 1 then rewrite(outFile)
		else if saveInd = 0 then append(outFile);
		{$I-}
		writeln; writeln(outFile, src);
		{$I+}
		if ioresult = 0 then writeln(language[14])
		else writeln(language[15], ioresult);
		close(outFile);
		clrscr;
		end;
	end;
end.